<template>
  <div id="qualityControldDetails" class="mainContent">
    <div class="information">
      <div class="row" v-if="!isShow">
        <div class="col-sm-9" style="display: flex;align-items: center;">
          <div class="col-sm-8" style="display: flex;align-items: center;">
            <span>所属月份：</span> <vue-datepicker-local format="YYYY-MM" v-model="emptyTime" clearable />
          </div>
          <div class="col-sm-4">
            <span>填写人：{{loginUser.Name}}</span>
          </div>
        </div>
        <div class="col-sm-3">
          <button @click="btnSave">保存</button>
        </div>
      </div>
      <div class="row" v-if="isShow">
        <div class="col-sm-9" style="display: flex;align-items: center;height:36px;">
          <div class="col-sm-8" style="display: flex;align-items: center;">
            <span>所属月份：{{qualityData.QCInfoDate}}</span>
          </div>
          <div class="col-sm-4">
            <span>填写人：{{loginUser.Name}}</span>
          </div>
        </div>
        <div class="col-sm-3">
          <button @click="btnSave">保存</button>
        </div>
      </div>
    </div>
    <!--机构配置信息【年报】-->
    <div class="qualitycontent">
      <div class="annualReport">
        <div class="title"><span>机构配置信息【年报】</span></div>
        <div class="row">
          <div class="col-sm-9">
            <div class="col-sm-6">
              <div>
                <p>全日制ICU专科医师数  <input type="number" v-model="qualityData.DoctorCount" /></p>
                <p>ICU护士总数  <input type="number" v-model="qualityData.NurseCount" /></p>
              </div>
            </div>
            <div class="col-sm-6">
              <div>
                <p>ICU床位数  <input type="number" v-model="qualityData.BedCount_ICU" /></p>
                <p>医院总床位数  <input type="number" v-model="qualityData.BedCount_Hispotal" /></p>
              </div>
            </div>
            <div class="col-sm-4 ratio" style="padding-right:0;"><p>ICU床位率 <span>{{BedRatio}}</span></p></div>
            <div class="col-sm-4 ratio"><p>ICU医师床位比 <span style="min-width:45px;margin-left:5px;">{{DoctorBedRatio}}</span></p></div>
            <div class="col-sm-4 ratio"><p>ICU护士床位比 <span style="min-width:45px;margin-left:5px;">{{NurseBedRatio}}</span></p></div>
          </div>
          <div class="col-sm-3">
            <div class="prompt">
              <p style="text-align:center;margin-bottom:10px;">备注</p>
              <p style="text-align:left;">一年上报一次，首次填写后再每月的表中自动显示前次的结果，可允许中间修改，每年一月强制进行修订和确认。</p>
            </div>
          </div>
        </div>
      </div>
      <!--患者收治情况-->
      <div class="admitted">
        <div class="title"><span>患者收治情况</span></div>
        <div class="row">
          <div class="col-sm-12 ratio"><p class="col-sm-5" style="padding-right:30px;text-align:right;margin-bottom:15px;">ICU患者收治率 <span>{{PatientRatio}}</span></p></div>
          <div class="col-sm-5">
            <p>ICU原有病人数  <input type="number" v-model="qualityData.PatientCount_ICU" /></p>
            <p>ICU新收治病人数  <input type="number" v-model="qualityData.NewPatientCount_ICU" /></p>
            <p>ICU收治患者总人数  <input type="number" v-model="PatientCount_ICU_Total" /></p>
          </div>
          <div class="col-sm-7">
            <div style="max-width:280px;">
              <p>医院原有病人数  <input type="number" v-model="qualityData.PatientCount_Hispotal" /></p>
              <p>医院新收治患者人数  <input type="number" v-model="qualityData.NewPatientCount_Hispotal" /></p>
              <p>医院收治患者总人数  <input type="number" v-model="PatientCount_Hispotal_Total" /></p>
            </div>
          </div>
          <div class="col-sm-12 ratio">
            <p>急性生理与慢病健康评分（APACHE II评分）≥ 15分患者收治率（入ICU24小时内）<span>{{ApacheII15Ratio}}</span></p>
          </div>
          <div class="col-sm-12">
            <p style="text-align:center;">入ICU 24小时内，APACHEⅡ评分≥15分患者数 <input type="number" v-model="qualityData.ApacheII15Count" /></p>
          </div>
          <div class="col-sm-12 ratio"><p class="col-sm-5" style="padding-right:30px;text-align:right;margin-bottom:15px;">ICU患者收治床日率 <span>{{PatientBedDayRatio}}</span></p></div>
          <div class="col-sm-5">
            <p>ICU患者收治总床日数  <input type="number" v-model="qualityData.PatientBedDayCount_ICU" /></p>
          </div>
          <div class="col-sm-7">
            <div style="max-width:280px;">
              <p>医院患者收治总床日数  <input type="number" v-model="qualityData.PatientBedDayCount_Hispotal" /></p>
            </div>
          </div>
        </div>
      </div>
      <!--感染性休克 3h/6h 集束化治疗完成率-->
      <div class="sepsis">
        <div class="title"><span>Sepsis</span></div>
        <div class="row">
          <div class="col-sm-9 col-lg-7 ratio">
            <p style="text-align:right;margin-bottom:5px;">感染性休克3h集束化治疗（bundle）完成率 <span>{{SepsisBundle3HRatio}}</span></p>
            <p style="text-align:right;">感染性休克6h集束化治疗（bundle）完成率 <span>{{SepsisBundle6HRatio}}</span></p>
          </div>
          <div class="col-sm-9 col-lg-7">
            <p>入ICU诊断为Spesis患者总数  <input type="number" v-model="qualityData.SepsisCountInICU" /></p>
            <p>全部完成 <span style="font-size:18px;">3h</span> bundle的患者数  <input type="number" v-model="qualityData.Bundle3HCount" /></p>
            <p>全部完成 <span style="font-size:18px;">6h</span> bundle的患者数  <input type="number" v-model="qualityData.Bundle6HCount" /></p>
          </div>
        </div>
      </div>
      <!--抗拒药物治疗前病原学送检率-->
      <div class="antibacterial">
        <div class="title"><span>抗菌药物</span></div>
        <div class="row">
          <div class="col-sm-9 col-lg-7 ratio">
            <p style="text-align:right;">抗菌药物治疗前病原学送检率 <span>{{AntibacterialCheckRatio}}</span></p>
          </div>
          <div class="col-sm-9 col-lg-7">
            <p>治疗性抗菌药物病例总数  <input type="number" v-model="qualityData.AntibacterialCount" /></p>
            <p>使用抗菌药物前病原学检验标本送检例数  <input type="number" v-model="qualityData.AntibacterialCheckCount" /></p>
          </div>
        </div>
      </div>
      <!--DVT 深静脉血栓预防率-->
      <div class="dvt">
        <div class="title"><span>DVT</span></div>
        <div class="row">
          <div class="col-sm-9 col-lg-7 ratio">
            <p style="text-align:right;">深静脉血栓（DVT）预防率 <span>{{DVTRatio}}</span></p>
          </div>
          <div class="col-sm-9 col-lg-7">
            <p>采取药物预防、非药物预防DVT措施的病例总数  <input type="number" v-model="qualityData.DVTCount" /></p>
          </div>
        </div>
      </div>
      <!--ICU 患者病死率，包括实际病死率和预计病死率、标化病死指数-->
      <div class="mortalityRate">
        <div class="title"><span>患者病死率</span></div>
        <div class="row">

          <div class="col-sm-9 col-lg-7">
            <p>ICU总死亡人数  <input type="number" v-model="qualityData.DeadCount" /></p>
            <p>临床死亡人数  <input type="number" v-model="qualityData.ClinicalDeadCount " /></p>
            <p>自动出院人数  <input type="number" v-model="qualityData.AutoLeaveDeadCount" /></p>
          </div>
          <div class="col-sm-9 col-lg-7 ratio" style="padding-right:40px;">
            <p style="text-align:right;">ICU患者实际病死率 <span>{{DeadRatio}}</span></p>
            <p style="text-align:right;">ICU患者预计病死率 <span>{{EstimatedDeadRatio}}</span></p>
          </div>
          <div class="col-sm-9 col-lg-7">
            <p>ICU收治患者入ICU预计病死率之和  <input type="number" v-model="qualityData.PatientDeadSum" /> <span style="position:absolute;margin-left:8px;margin-top:4px;">%</span> </p>
          </div>
          <div class="col-sm-9 col-lg-7 ratio" style="padding-right:40px;">
            <p style="text-align:right;">ICU重症患者标化病死指数（StandardizedMortality Ratio） <span>{{StandardizedMorthalityRatio}}</span></p>
          </div>
        </div>
      </div>
      <!--非计划转入和重返事件-->
      <div class="unplanned">
        <div class="title"><span>非计划转入和重返事件</span></div>
        <div class="row">
          <div class="col-sm-9 col-lg-7 ratio" style="padding-right:40px;">
            <p style="text-align:right;">非计划转入ICU率 <span>{{UnPlanInICURatio}}</span></p>
            <p style="text-align:right;">转出ICU后 48h 内重返率 <span>{{ReInICU48Ratio}}</span></p>
          </div>
          <div class="col-sm-9 col-lg-7">
            <p>非计划转入ICU患者数（术后）  <input type="number" v-model="qualityData.UnPlanCount_Operation" /></p>
            <p>转入ICU患者总数（术后）  <input type="number" v-model="qualityData.InICUCount_Operation" /></p>
            <p>转出ICU后48h内重返ICU患者数  <input type="number" v-model="qualityData.ReInICU48Count" /></p>
            <p>ICU转出患者总数  <input type="number" v-model="qualityData.OutICUCount" /></p>
          </div>
        </div>
      </div>
      <!--气管插管事件：包括非计划气管插管拔管率和 48 小时再插率：-->
      <div class="trachea">
        <div class="title"><span>气管插管事件</span></div>
        <div class="row">
          <div class="col-sm-9 col-lg-7 ratio" style="padding-right:40px;">
            <p style="text-align:right;">非计划气管插管拔管率 <span>{{UnPlanTracheaIsueRatio}}</span></p>
          </div>
          <div class="col-sm-9 col-lg-7">
            <p>非计划气管插管脱出次数  <input type="number" v-model="qualityData.UnPlanTracheaIsueCount" /></p>
            <p>ICU患者气管插管拔管总例数  <input type="number" v-model="qualityData.TracheaPullOutCount" /></p>
          </div>
          <div class="col-sm-9 col-lg-7 ratio" style="padding-right:40px;">
            <p style="text-align:right;">气管插管拔管后48h内再插管率 <span>{{RedoTrachea48HRatio}}</span></p>
          </div>
          <div class="col-sm-9 col-lg-7">
            <p>计划拔管后48h内再插管例数  <input type="number" v-model="qualityData.RedoTrachea48HCount" /></p>
          </div>
        </div>
      </div>
      <!--三管感染率，包括气管类插管、尿路类插管和血管内插管导致的相应的感染 发生-->
      <div class="threeTubes">
        <div class="title"><span>三管感染率</span></div>
        <div class="row">
          <div class="col-sm-9 col-lg-7 ratio" style="padding-right:40px;">
            <p style="text-align:right;">ICU呼吸机相关性肺炎（VAP）发病率 <span>{{VAPRatio}}</span></p>
          </div>
          <div class="col-sm-9 col-lg-7">
            <p>ICU呼吸机相关肺炎病人总例数  <input type="number" v-model="qualityData.VAPCount" /></p>
            <p>ICU总机械通气天数 <input type="number" v-model="qualityData.VAPMachineDaysCount" /></p>
          </div>
          <div class="col-sm-9 col-lg-7 ratio" style="padding-right:40px;">
            <p style="text-align:right;">ICU血管内导管相关血流感染（CRBSI）发病率 <span>{{CRBSIRatio}}</span></p>
          </div>
          <div class="col-sm-9 col-lg-7">
            <p>ICU中心静脉导管相关性血流感染总例数  <input type="number" v-model="qualityData.CRBSICount" /></p>
            <p>ICU中心静脉导管总天数 <input type="number" v-model="qualityData.CRBSIDaysCount" /></p>
          </div>
          <div class="col-sm-9 col-lg-7 ratio" style="padding-right:40px;">
            <p style="text-align:right;">ICU导尿管相关泌尿系感染（CAUTI）发病率 <span>{{CAUTIDaysRatio}}</span></p>
          </div>
          <div class="col-sm-9 col-lg-7">
            <p>ICU导尿管相关泌尿系统感染总例数  <input type="number" v-model="qualityData.CAUTICount" /></p>
            <p>ICU尿管留置总天数 <input type="number" v-model="qualityData.CAUTIDaysCount " /></p>
          </div>
        </div>
      </div>
    </div>
    <loading v-if="isLoading"></loading>
  </div>
</template>
<script>
  import { formatDate } from "@/components/common/date"; //引入时间转换JS
  import { apiNewQCReport, apiGetCCQCReport, apiUpdateQCReport} from '@/api/api';  //引入保存质控信息数据方法
  import VueDatepickerLocal from '@/components/datepicker/VueDatepickerLocal'  //引入时间选择组件
  import Bus from "@/components/common/bus"; //引入公共媒介JS BUS
  import loading from '@/components/loading/loading'
  export default {
    data() {
      return {
        loginUser: {}, //存储当前登录用户的名字
        qualityData: {}, //存储当前详情页的所有数据
        emptyTime: '' , 
        QCInfoDate: '' ,//选择的时间
        isShow: true,
        isLoading : false
      }
    },
    watch: {
      QCInfoDate: {
        handler(curVal, oldVal) {
          if (curVal == '') {
            this.qualityData.QCInfoDate = '';
          } else {
            this.qualityData.QCInfoDate = curVal;
            //console.log(this.qualityData.QCInfoDate)
          }
        }
      }
    },
    computed: {
      BedRatio: function () {   // ICU患者床位率
        let bedNum = '0.00%';
        //console.log(this.qualityData.BedCount_Hispotal)
        if (this.qualityData.BedCount_Hispotal == undefined || this.qualityData.BedCount_Hispotal == 0 || this.qualityData.BedCount_Hispotal == '') {
          return bedNum;
        } else {
          return (Math.round(this.qualityData.BedCount_ICU / this.qualityData.BedCount_Hispotal * 10000) / 100.00).toFixed(2) + "%";// 小数点后两位百分比
        }
      },
      DoctorBedRatio: function () {  //ICU医师床位比
        let rslt = "0:0";
        if (this.qualityData.BedCount_ICU == undefined || this.qualityData.BedCount_ICU == 0 || this.qualityData.BedCount_ICU == '') {
          return rslt
        } else {
          let m = this.Euclidean_nonRecursion(this.qualityData.DoctorCount,this.qualityData.BedCount_ICU);
        if (m != 0) {
          rslt = this.qualityData.DoctorCount / m + ":" + this.qualityData.BedCount_ICU / m;
        }
        else {
          rslt = this.qualityData.DoctorCount / m + ":" + this.qualityData.BedCount_ICU;
        }
          return rslt;
        }
      },
      NurseBedRatio: function () {  //ICU护士床位比
        let rslt = "0:0";
        if (this.qualityData.BedCount_ICU == undefined || this.qualityData.BedCount_ICU == 0 || this.qualityData.BedCount_ICU == '') {
          return rslt
        } else {
          let m = this.Euclidean_nonRecursion(this.qualityData.NurseCount, this.qualityData.BedCount_ICU);
          if (m != 0) {
            rslt = this.qualityData.NurseCount / m + ":" + this.qualityData.BedCount_ICU / m;
          }
          else {
            rslt = this.qualityData.NurseCount / m + ":" + this.qualityData.BedCount_ICU;
          }
          return rslt;
        }
      },
      PatientCount_ICU_Total: function () { //ICU收治患者总人数
        if ((this.qualityData.PatientCount_ICU == undefined && this.qualityData.NewPatientCount_ICU != undefined )|| (this.qualityData.PatientCount_ICU == 0 && this.qualityData.NewPatientCount_ICU != 0)) {
          return this.qualityData.NewPatientCount_ICU
        } else if ((this.qualityData.PatientCount_ICU != undefined && this.qualityData.NewPatientCount_ICU == undefined) || (this.qualityData.PatientCount_ICU != 0 && this.qualityData.NewPatientCount_ICU == 0)) {
          return this.qualityData.PatientCount_ICU
        } else if (this.qualityData.PatientCount_ICU == undefined && this.qualityData.NewPatientCount_ICU == undefined) {
          return '';
        }else {
          return parseFloat(this.qualityData.PatientCount_ICU) + parseFloat(this.qualityData.NewPatientCount_ICU);
        }
        
      },
      PatientCount_Hispotal_Total: function () {  //医院收治患者总人数
        if ((this.qualityData.PatientCount_Hispotal == undefined && this.qualityData.NewPatientCount_Hispotal != undefined) || (this.qualityData.PatientCount_Hispotal == 0 && this.qualityData.NewPatientCount_Hispotal != 0)) {
          return this.qualityData.NewPatientCount_Hispotal
        } else if ((this.qualityData.PatientCount_Hispotal != undefined && this.qualityData.NewPatientCount_Hispotal == undefined) || (this.qualityData.PatientCount_Hispotal != 0 && this.qualityData.NewPatientCount_Hispotal == 0)) {
          return this.qualityData.PatientCount_Hispotal
        } else if (this.qualityData.PatientCount_Hispotal == undefined && this.qualityData.NewPatientCount_Hispotal == undefined) {
          return '';
        } else {
          return parseFloat(this.qualityData.PatientCount_Hispotal) + parseFloat(this.qualityData.NewPatientCount_Hispotal);
        }
      },
      PatientRatio: function () {  //ICU患者收治率
        let rslt = '0.00%';
        //console.log(this.PatientCount_Hispotal_Total)
        if (this.PatientCount_Hispotal_Total == 0 || this.PatientCount_Hispotal_Total == undefined || this.PatientCount_Hispotal_Total == '') {
          return rslt;
        } else {
          return (Math.round(this.PatientCount_ICU_Total / this.PatientCount_Hispotal_Total * 10000) / 100.00).toFixed(2) + "%";// 小数点后两位百分比
        }
      },
      ApacheII15Ratio: function () {//急性生理与慢性健康评分（APACHEⅡ评分）≥15分患者收治率（入ICU24小时内）
        let rslt = '0.00%';
        if (this.qualityData.ApacheII15Count == undefined || this.qualityData.ApacheII15Count == 0) {
          return rslt;
        } else {
          if (this.PatientCount_ICU_Total == 0 || this.PatientCount_ICU_Total == undefined || this.PatientCount_ICU_Total == '') {
            return rslt;
          } else {
            return (Math.round(this.qualityData.ApacheII15Count / this.PatientCount_ICU_Total * 10000) / 100.00).toFixed(2) + "%";// 小数点后两位百分比
          }
          
        }
      },
      PatientBedDayRatio: function () {    //ICU患者收治床日率
        let rslt = '0.00%';
        if (this.qualityData.PatientBedDayCount_Hispotal == undefined || this.qualityData.PatientBedDayCount_Hispotal == 0 || this.qualityData.PatientBedDayCount_Hispotal == '') {
          return rslt;
        } else {
          return (Math.round(this.qualityData.PatientBedDayCount_ICU / this.qualityData.PatientBedDayCount_Hispotal * 10000) / 100.00).toFixed(2) + "%";// 小数点后两位百分比
        }
      },
      SepsisBundle3HRatio: function () {  //感染性休克3h集束化治疗（bundle）完成率
        let rslt = '0.00%';
        if (this.qualityData.SepsisCountInICU == undefined || this.qualityData.SepsisCountInICU == 0 || this.qualityData.SepsisCountInICU == '') {
          return rslt;
        } else {
          if(this.qualityData.Bundle3HCount == undefined || this.qualityData.Bundle3HCount == 0 || this.qualityData.Bundle3HCount == '') {
            return rslt;
          } else {
          return (Math.round(this.qualityData.Bundle3HCount / this.qualityData.SepsisCountInICU * 10000) / 100.00).toFixed(2) + "%";// 小数点后两位百分比
    }
  }
      },
      SepsisBundle6HRatio: function () {   //感染性休克6h集束化治疗（bundle）完成率
        let rslt = '0.00%';
        if (this.qualityData.SepsisCountInICU == undefined || this.qualityData.SepsisCountInICU == 0 || this.qualityData.SepsisCountInICU == '') {
          return rslt;
        } else {
          if (this.qualityData.Bundle6HCount == undefined || this.qualityData.Bundle6HCount == 0 || this.qualityData.Bundle6HCount == '') {
            return rslt;
          } else {
          return (Math.round(this.qualityData.Bundle6HCount / this.qualityData.SepsisCountInICU * 10000) / 100.00).toFixed(2) + "%";// 小数点后两位百分比
          }
          }
      },
      AntibacterialCheckRatio: function () { //ICU抗菌药物治疗前病原学送检率
        let rslt = '0.00%';
        if (this.qualityData.AntibacterialCount == undefined || this.qualityData.AntibacterialCount == 0 || this.qualityData.AntibacterialCount == '') {
          return rslt;
        } else {
          if (this.qualityData.AntibacterialCheckCount == undefined || this.qualityData.AntibacterialCheckCount == 0 || this.qualityData.AntibacterialCheckCount == '') {
            return rslt;
          } else {
            return (Math.round(this.qualityData.AntibacterialCheckCount / this.qualityData.AntibacterialCount * 10000) / 100.00).toFixed(2) + "%";// 小数点后两位百分比
          }
        }
      },
      DVTRatio: function () {  //ICU深静脉血栓（DVT）预防率
        let rslt = '0.00%';
        if (this.PatientCount_ICU_Total == undefined || this.PatientCount_ICU_Total == 0 || this.PatientCount_ICU_Total == '') {
          return rslt;
        } else {
          if (this.qualityData.DVTCount == undefined || this.qualityData.DVTCount == 0 || this.qualityData.DVTCount == '') {
            return rslt;
          } else {
            return (Math.round(this.qualityData.DVTCount / this.PatientCount_ICU_Total * 10000) / 100.00).toFixed(2) + "%";// 小数点后两位百分比
          }
        }
      },
      DeadRatio: function () {  //ICU患者实际病死率
        let rslt = '0.00%';
        if (this.PatientCount_ICU_Total == undefined || this.PatientCount_ICU_Total == 0 || this.PatientCount_ICU_Total == '') {
          return rslt;
        } else {
          if (this.qualityData.DeadCount == undefined || this.qualityData.DeadCount == 0 || this.qualityData.DeadCount == '') {
            return rslt;
          } else {
            return (Math.round(this.qualityData.DeadCount / this.PatientCount_ICU_Total * 10000) / 100.00).toFixed(2) + "%";// 小数点后两位百分比
          }
        }
      },
      EstimatedDeadRatio: function () {  //ICU患者预计病死率
        let rslt = '0.00%';
        if (this.PatientCount_ICU_Total == undefined || this.PatientCount_ICU_Total == 0 || this.PatientCount_ICU_Total == '') {
          return rslt;
        } else {
          if (this.qualityData.PatientDeadSum == undefined || this.qualityData.PatientDeadSum == 0 || this.qualityData.PatientDeadSum  == '') {
            return rslt;
          } else {
            return (Math.round(this.qualityData.PatientDeadSum  / this.PatientCount_ICU_Total * 10000) / 100.00).toFixed(2) + "%";// 小数点后两位百分比
          }
        }
      },
      StandardizedMorthalityRatio: function () {   //ICU患者标化病死指数
        let rslt = '0.00%';
        if (this.ExpectedDeadRatio != '0.00%') {
          if (this.DeadRatio != '0.00%') {
            return (Math.round((Math.round(this.qualityData.DeadCount / this.PatientCount_ICU_Total * 10000) / 100.00).toFixed(2) / (Math.round(this.qualityData.PatientDeadSum / this.PatientCount_ICU_Total * 10000) / 100.00).toFixed(2) * 10000) / 100.00).toFixed(2) + "%";// 小数点后两位百分比
          } else {
            return rslt;
          }
        } else {
          return rslt;
        }
      },
      UnPlanInICURatio: function () { //非计划转入ICU率
        let rslt = '0.00%';
        if (this.qualityData.InICUCount_Operation == undefined || this.qualityData.InICUCount_Operation == 0 || this.qualityData.InICUCount_Operation == '') {
          return rslt;
        } else {
          if (this.qualityData.UnPlanCount_Operation == "" || this.qualityData.UnPlanCount_Operation == undefined || this.qualityData.UnPlanCount_Operation == '') {
            return rslt;
          } else {
            return (Math.round(this.qualityData.UnPlanCount_Operation / this.qualityData.InICUCount_Operation * 10000) / 100.00).toFixed(2) + "%";// 小数点后两位百分比
          }
        }
      },
      ReInICU48Ratio: function () { //转出ICU后48h内重返率
        let rslt = '0.00%';
        if (this.qualityData.OutICUCount == undefined || this.qualityData.OutICUCount == 0 || this.qualityData.OutICUCount == '') {
          return rslt;
        } else {
          if (this.qualityData.ReInICU48Count == "" || this.qualityData.ReInICU48Count == undefined || this.qualityData.ReInICU48Count == '') {
            return rslt;
          } else {
            return (Math.round(this.qualityData.ReInICU48Count / this.qualityData.OutICUCount * 10000) / 100.00).toFixed(2) + "%";// 小数点后两位百分比
          }
        }
      },
      UnPlanTracheaIsueRatio: function () {  // ICU非计划气管插管拔管率
        let rslt = '0.00%';
        if (this.qualityData.TracheaPullOutCount == undefined || this.qualityData.TracheaPullOutCount == 0 || this.qualityData.TracheaPullOutCount == '') {
          return rslt;
        } else {
          if (this.qualityData.UnPlanTracheaIsueCount == "" || this.qualityData.UnPlanTracheaIsueCount == undefined || this.qualityData.UnPlanTracheaIsueCount == '') {
            return rslt;
          } else {
            return (Math.round(this.qualityData.UnPlanTracheaIsueCount / this.qualityData.TracheaPullOutCount * 10000) / 100.00).toFixed(2) + "%";// 小数点后两位百分比
          }
        }
      },
      RedoTrachea48HRatio: function () {  //ICU气管插管拔管后48h内再插管率
        let rslt = '0.00%';
        if (this.qualityData.TracheaPullOutCount == undefined || this.qualityData.TracheaPullOutCount == 0 || this.qualityData.TracheaPullOutCount == '') {
          return rslt;
        } else {
          if (this.qualityData.RedoTrachea48HCount == "" || this.qualityData.RedoTrachea48HCount == undefined || this.qualityData.RedoTrachea48HCount == '') {
            return rslt;
          } else {
            return (Math.round(this.qualityData.RedoTrachea48HCount / this.qualityData.TracheaPullOutCount * 10000) / 100.00).toFixed(2) + "%";// 小数点后两位百分比
          }
        }
      },
      VAPRatio: function () {  //ICU呼吸机相关性肺炎（VAP）发病率
        let rslt = '0.00‰';
        if (this.qualityData.VAPMachineDaysCount == undefined || this.qualityData.VAPMachineDaysCount == 0 || this.qualityData.VAPMachineDaysCount == '') {
          return rslt;
        } else {
          if (this.qualityData.VAPCount == undefined || this.qualityData.VAPCount == 0 || this.qualityData.VAPCount == '') {
            return rslt;
          } else {
            return (Math.round(this.qualityData.VAPCount / this.qualityData.VAPMachineDaysCount * 100000) / 100.00) + "‰";
          }
        }
      },
      CRBSIRatio: function () {  //ICU血管内导管相关血流感染（CRBSI）发病率
        let rslt = '0.00‰';
        if (this.qualityData.CRBSIDaysCount == undefined || this.qualityData.CRBSIDaysCount == 0 || this.qualityData.CRBSIDaysCount == '') {
          return rslt;
        } else {
          if (this.qualityData.CRBSICount == undefined || this.qualityData.CRBSICount == 0 || this.qualityData.CRBSICount == '') {
            return rslt;
          } else {
            return (Math.round(this.qualityData.CRBSICount / this.qualityData.CRBSIDaysCount * 100000) / 100.00) + "‰";
          }
        }
      },
      CAUTIDaysRatio: function () {  //ICU导尿管相关泌尿系感染（CAUTI）发病率
        let rslt = '0.00‰';
        if (this.qualityData.CAUTIDaysCount == undefined || this.qualityData.CAUTIDaysCount == 0 || this.qualityData.CAUTIDaysCount == '') {
          return rslt;
        } else {
          if (this.qualityData.CAUTICount == undefined || this.qualityData.CAUTICount == 0 || this.qualityData.CAUTICount == '') {
            return rslt;
          } else {
            return (Math.round(this.qualityData.CAUTICount / this.qualityData.CAUTIDaysCount * 100000) / 100.00) + "‰";
          }
        }
      }
    },
    created() {
      this.loginUser = JSON.parse(sessionStorage.getItem('user'));
      this.getQualityControld();
      ////console.log(standardDate(new Date()).substring(0, 7));
      //this.qualityData.QCInfoDate = standardDate(new Date()).substring(0, 7);
    },
    mounted() {
    
      Bus.$on("timePicker", e => {
        this.QCInfoDate = e.trim();
      });
    },
    methods: {
      Euclidean_nonRecursion(m, n) {
        while (n != 0) {
         let r = m % n;
          m = n;
          n = r;
        }
        return m;
     
      },
      getQualityControld() {
        if (this.$route.query.status == 1) {  //状态码为0时则为新增否则为编辑
         
          apiGetCCQCReport({
            id: this.$route.query.id
          })
            .then(res => {
              if (res == '') {
                //console.log(res)
                alert('当前数据有问题，请联系管理员');
              } else {
                this.qualityData = res;
                this.isShow = true; //当为编辑时时间固定的
                this.qualityData.QCInfoDate = this.formatDates(res.QCInfoDate);
                //console.log(JSON.stringify(this.qualityData == ''))
              } 
            })
        } else {
          this.isShow = false; //当为新增时 时间 是可以选择的
          return false;
        }
      },

      btnSave() {
        //console.log(JSON.stringify(this.qualityData));
        this.isLoading = true;
        if (this.$route.query.status == 0) { //状态码为0时则为新增否则为编辑
          apiNewQCReport({
            reportJsonStr: JSON.stringify(this.qualityData)
          })
            .then(res => {
              if (res.ResultCode == -1) {
                this.$toast.center(res.Message);
              } else {
                this.$toast.center(res.Message);
                this.$router.push({
                  path: '/qualityControl/qualityControldChart',
                  query: {item : 2}
                })
              }
            })
        } else {
          apiUpdateQCReport({
            reportJsonStr: JSON.stringify(this.qualityData)
          })
            .then(res => {
              if (res.ResultCode == -1) {
                this.$toast.center(res.Message);
              } else {

                this.$toast.center(res.Message);
                this.$router.push({
                  path: '/qualityControl/qualityControldChart',
                  query: { item: 2 }
                })
              }
           
            })
        }
       
      },
      formatDates(time) {
        if (time == '') {
          return ''
        } else {
          var date = new Date(parseInt(time.substring(6, 19)));
          return formatDate(date, "yyyy-MM");
        }
    },
    },
    components: {
      VueDatepickerLocal,
      loading
    }
}
</script>
<style scoped>
  #qualityControldDetails {
    padding:20px 0;
  }
  .information{
    padding-left:40px;
    font-size:16px;
    margin-bottom:10px;
  }
    .information span:first-child{
      margin-right:10px;
    }
    .information span {
      margin-right: 150px;
    }
    .information button {
      padding: 7px 15px;
      background-color: #11a7f3;
      color:#fff;
    }
  
  .title {
    font-size: 18px;
    padding-left: 20px;
    margin-bottom: 15px;
    margin-top: 15px;
  }
  .annualReport .title{
    margin-top:0;
  }
  .title span:before {
    content: "";
    display: inline-block;
    width: 3px;
    height: 20px;
    border-radius: 8px;
    margin-right: 8px;
    background: #11a7f3;
    vertical-align: text-top;
  }
  .qualitycontent{
    height:calc(100% - 30px);
    padding-bottom:20px;
    overflow-y:auto;
  }
  input{
    width:80px;
    height:27px;
    font-size:17px;
    text-align:center;
    border:1px solid #ccc;
    box-shadow:0 -1px 5px #ccc;
    border-radius:4px;
    margin-left:15px;
  }
  .qualitycontent .annualReport .row {
    display: flex;
    align-items: center;
    padding: 15px 5px 15px 15px;
    background-color: #f3f3f3;
  }
  .qualitycontent .row  p {
    text-align: right;
    margin-bottom: 10px;
  }
  .qualitycontent .row .col-sm-6 p:last-child {
    margin-bottom: 25px;
  }
  .qualitycontent .ratio {
    font-size: 15px;
    color: #11a7f3;
    font-weight:bold;
  }
  .row{
    margin:0;
  }
  .qualitycontent .ratio p{
    text-align:center;
  }
  .qualitycontent .ratio p span{
    display:inline-block;
    min-width:60px;
    color:#f00;
    font-size:18px;
    margin-left:15px;
  }
  .prompt {
    max-width: 180px;
    height: 100%;
    background-color: #871C22;
    color:#fff;
    font-size:12px;
    padding:10px;
  }
</style>
